package com.haoma.config;

import com.haoma.interceptor.LoginMvcInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;

/**
 * Description: 注册webMvc的配置
 */
@Configuration
public class WebMvcConfiguration extends WebMvcConfigurationSupport {

    @Autowired
    private StringRedisTemplate stringRedisTemplate;

    /**
     * 添加登录拦截器
     *
     * @param registry
     */
    protected void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new LoginMvcInterceptor(stringRedisTemplate))
                .excludePathPatterns("/admin/user/login",
                        "/admin/user/logout",
                        "/admin/user/view",
                        "/admin/user/reset",
                        "/web/**",
                        "/admin/minio/**",
                        "/admin/article/add")
                .addPathPatterns("/**");
    }
}
